var PAGE_CUSTOM = 'art-custom';
/**
 * 客户详情页
 * @type _L5.Anonym$0
 */
App.View.CustomPage = (function (lng, App) {

    var _router = App.Router;
    var _template = App.Data.Template;
    var _ele = App.Data.Element;

    var $ = lng.dom;
    var $_doms = App.Data.Doms[_ele.SECTIONS.CUSTOM];
    var $_section = $_doms.section;
    var $_maturity = $_doms.maturity;
    var $_visits = $_doms.visits;

    var loadPage = function () {

    };

    var showAddCustom = function () {
        _cleanPage();
        $_maturity.hide();
        $_visits.hide();
    };

    var showCustomDetails = function (custom) {
        _cleanPage();
        _setCustomDetails(custom);
        $_maturity.show();
        $_visits.show();
    };

    /**
     * 清理页面
     * @private
     */
    var _cleanPage = function () {
        $_doms.custom_name.val('');
        $_doms.custom_addr.val('');
        $_doms.person_group.find('div').remove();
        $_doms.product_group.find('div').remove();
    };

    /**
     * 显示客户
     * @param custom
     * @private
     */
    var _setCustomDetails = function (custom) {
        $_doms.custom_name.val(custom.name);
        $_doms.custom_addr.val(custom.addr);
        _setPersonInputs(custom.persons);
        _setDealInputs(custom.deals);
    };

    var _setPersonInputs = function (persons) {
        var size = persons.length;
        for (var i = size; --i >= 0;) {
            $_doms.person_group.append(_template.INPUT_GROUP.format('联系人', '联系方式'));
        }
        var nameDoms = $_doms.person_group.find('.first_input');
        var telDoms = $_doms.person_group.find('.second_input');
        for (var i = 0; i < size; i++) {
            nameDoms[i].value = persons[i].name;
            telDoms[i].value = persons[i].tel;
        }
    };

    var _setDealInputs = function (deals) {
        var size = deals.length;
        for (var i = size; --i >= 0;) {
            $_doms.product_group.append(_template.INPUT_GROUP_2.format('产品', '金额'));
        }
        var productDoms = $_doms.product_group.find('.first_input');
        var moneyDoms = $_doms.product_group.find('.second_input');
        for (var i = 0; i < size; i++) {
            productDoms[i].value = deals[i].product;
            moneyDoms[i].value = deals[i].money;
        }
    };

    return {
        loadPage:loadPage,
        showAddCustom:showAddCustom,
        showCustomDetails:showCustomDetails
    };
})(Lungo, App);